<%--
  Created by IntelliJ IDEA.
  User: New
  Date: 2021/5/7
  Time: 15:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录页面</title>
</head>
<body>
<form>
    <label>用户名:</label> <input name="username" id="username"/>
    <label>密码:</label> <input name="password" id="password"/>
    <button type="button" id="btnLogin">登录</button>
</form>

<div id="err"></div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script>

    $(document).ready(function () {
        $('#btnLogin').bind('click', btnLoginClick)
    })
    function btnLoginClick() {

        $.ajax({
            url: 'http://localhost:8080/java_web_war_exploded/sys/login',
            method: 'post',
            dataType: 'json',
            data: {
                username: $('#username').val(),
                password: $('#password').val()
            }, success:function (data) {
                if (data.flag) {
                    window.location.href = "http://localhost:8080/java_web_war_exploded/index.jsp"
                } else {
                    $('#err').text("用户名或者密码错误！")
                }
            }
        })
    }
</script>

</html>
